import time
from xiaopy import *
from cotc import COTC

try:
    # ui = xp.ui()
    # region = ui.stringValue("region")
    region = 'tw'
    c = COTC(region)
except Exception as e:
    xp.toast(e)


def run_script():
    sucess = False
    while True:
        if not sucess:
            print("start")
            c.tap_jm_fuyulinghun_btn()
            print("1")
            time.sleep(0.5)
            c.tap_tc_queren_btn()
            print("2")
            c.wait_tc_baoliu_ok_btn_dis()
            if c.check_tc_baoliu_xiyou():
                print("3")
                break
            else:
                xp.tap(620, 300)
                print("4")
            time.sleep(0.5)
            c.tap_tc_baoliu_ok_btn()
            print("5")
            time.sleep(1)
            c.tap_tc_xuanzeqitalinghun_btn()
            print("6")
            time.sleep(1)

run_script()
